package com.zxmr.webclient.upload;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import com.zxmr.domain.file.SystemFolderType;
import com.zxmr.domain.service.ResourceService;

public class UploaderFactory {

	static Map<String,Uploader> uploaders = new HashMap<String,Uploader>();
	static{
		uploaders.put("main", new DefaultUploader());
	}
	public static void registerUploader(Uploader uploader)
	{
		
	}
	public static Uploader getUploader(String uploadType)
	{
		return uploaders.get(uploadType);
	}
	public static void init()
	{
		DefaultUploader.initSupportFormat();
		ResourceService service = new ResourceService();
		List<SystemFolderType> types = service.queryAllSystemFolderType();
		if(types != null)
		{
			for(SystemFolderType type : types)
			{
				try
				{
					@SuppressWarnings("unchecked")
					Class<? extends SystemFolderUploader> instanceClass = (Class<? extends SystemFolderUploader>) Class.forName(type.getUploader());
					
					SystemFolderUploader uploader = instanceClass.newInstance();
					uploader.setFolderType(type.getType());
					uploaders.put(type.getType(), uploader);
				}catch(Exception e)
				{
					e.printStackTrace();
				}

			}
		}
	}
}
